/**********************************************************************
* Filename: Classe.java
* Created: 2013/05/30
* @author Fernando Brito e Abreu
**********************************************************************/
package org.quasar.airNova.businessLayer;

import org.quasar.airNova.persistenceLayer.Database;

import java.util.Set;
import java.util.HashSet;

public class Classe
{
	
	/***********************************************************
	* @return all instances of class Classe
	***********************************************************/
	public static Set<Classe> allInstances()
	{
		return Database.allInstances(Classe.class);
	}
	
	private TipoClasse tipo;
	
	/**********************************************************************
	* Default constructor
	**********************************************************************/
	public Classe()
	{
	}
	
	/**********************************************************************
	* Parameterized constructor
	* @param tipo the tipo to initialize
	**********************************************************************/
	public Classe(TipoClasse tipo)
	{
		this.tipo = tipo;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the tipo of the classe
	**********************************************************************/
	public TipoClasse tipo()
	{
		return tipo;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param tipo the tipo to set
	**********************************************************************/
	public void setTipo(TipoClasse tipo)
	{
		this.tipo = tipo;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Classe[1] <-> Bilhete[*]
	* @return the bilhetes of the classe
	**********************************************************************/
	public Set<Bilhete> bilhetes()
	{
		Set<Bilhete> result = new HashSet<Bilhete>();
		for (Bilhete x : Bilhete.allInstances())
			if (x.classe()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* ONE2MANY multiple setter for Classe[1] <-> Bilhete[*]
	* @param bilhetes the bilhetes to set
	**********************************************************************/
	public void setBilhetes(Set<Bilhete> bilhetes)
	{
		for (Bilhete x : bilhetes)
			x.setClasse(this);
	}
	
	/**********************************************************************
	* ONE2MANY single setter for Classe[1] <-> Bilhete[*]
	* @param bilhete the bilhete to add
	**********************************************************************/
	public void addBilhetes(Bilhete bilhete)
	{
		bilhete.setClasse(this);
	}
	
	/**********************************************************************
	* MEMBER2ASSOCIATIVE getter for Classe[*] <-> Capacidade[*]
	* @return the capacidade of the classe
	**********************************************************************/
	public Set<Capacidade> capacidade()
	{
		Set<Capacidade> result = new HashSet<Capacidade>();
		for (Capacidade x : Capacidade.allInstances())
			if (x.classe()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* MEMBER2ASSOCIATIVE setter for Classe[*] <-> Capacidade[*]
	* @param capacidade the capacidade to set
	**********************************************************************/
	public void setCapacidade(Set<Capacidade> capacidade)
	{
		for (Capacidade x : capacidade)
			x.setClasse(this);
	}
	
	/**********************************************************************
	* MEMBER2MEMBER getter for Classe[*] <-> Aviao[*]
	* @return the aviao of the classe
	**********************************************************************/
	public Set<Aviao> aviao()
	{
		Set<Aviao> result = new HashSet<Aviao>();
		for (Capacidade x : Capacidade.allInstances())
			if (x.classe()  ==  this)
				result.add(x.aviao());
		return result;
	}
	
	/**********************************************************************
	* MEMBER2MEMBER setter for Classe[*] <-> Aviao[*]
	* @param aviao the aviao to set
	**********************************************************************/
	public void setAviao(Set<Aviao> aviao)
	{
		for (Aviao t : aviao)
			for (Capacidade x : Capacidade.allInstances())
				if (x.classe() == this)
					x.setAviao(t);
	}
	
	/**********************************************************************
	* Object serializer
	**********************************************************************/
	public String toString()
	{
		return "Classe [tipo=" + tipo + "]";
	}
	
}
